package com.yijietong.yiliao.doctor.controller;

import com.qiniu.util.Auth;
import com.qiniu.util.StringUtils;
import com.yijietong.yiliao.doctor.constants.Constants;
import com.yijietong.yiliao.doctor.pojo.BaseBean;
import com.yijietong.yiliao.doctor.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 功能详细描述
 *
 * @author 奇奇
 * @version create at 2017-11-21  16:49
 */
@Controller
@RequestMapping("/qiniu")
public class QiNiuController  {
    @RequestMapping(value = "/getUploadToken", method = RequestMethod.POST)
    @ResponseBody
    public BaseBean<String> getUploadToken(@RequestParam(value = "folderType") String folderType) {
        BaseBean<String> baseBean = new BaseBean<>();
        //密钥配置
        Auth auth = Auth.create(Constants.ACCESS_KEY, Constants.SECRET_KEY);
        String bucketname = ""; // 上传的文件夹名字
        switch (folderType) {
            case "1":
                bucketname = "yiliaodoctor";
                break;
            case "2":
                bucketname = "yiliaodoctor";
                break;
            case "3":
                bucketname = "yiliaodoctor";
                break;
            default:
                bucketname = "yiliaodoctor";
                break;
        }
        String token =  auth.uploadToken(bucketname);
        if(StringUtils.isNullOrEmpty(token)) {
            baseBean.setCode(0);
            baseBean.setMessage("获取成功");
            baseBean.setData(token);
        } else {
            baseBean.setCode(71);
            baseBean.setMessage("获取失败");
        }
        return baseBean;
    }
}
